import { get } from "core-js/core/dict";
import requests from "./requests";
import { getToken } from '@/utils/token';

// 登录
export const reqUserLogin = (data) => {
    const config = {
        headers: {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Content-Type': 'application/json'
        }
    };
    return requests({
        url: "/user/login",
        method: "POST",
        data,
        headers: config.headers
    })
}

// 注册
export const reqUserRegister = (data) => {
    const config = {
        headers: {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Content-Type': 'application/json'
        }
    };
    return requests({
        url: "/user/register",
        method: "POST",
        data,
        headers: config.headers
    })
}

// 获取首页导航菜单数据
export const reqNavMenu = () => {
    return requests({
        // TODO
        url: "",
        method: "GET",
    })
}

// 上传视频
export const reqUploadVideo = (data) => {
    const config = {
        headers: {
            'token': getToken(),
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            ...data.getHeaders()
        }
    };
    return requests({
        url: "/video/upload",
        method: "POST",
        data,
        headers: config.headers
    })
}

// 上传文字
export const reqUploadText = (data) => {
    return requests({
        // TODO
        url: "",
        method: "POST",
        data
    })
}

// 获取热榜
export const reqHotVideo = () => {
    const config = {
        headers: {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        }
    };
    return requests({
        url: "video/hotVideo?type=1",
        method: "GET",
        headers: config.headers
    })
}

// 获取视频列表
export const reqVideoList = (currentPage, pageSize) => {
    const config = {
        headers: {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        }
    };
    return requests({
        url: `/video/page?currentPage=${currentPage}&pageSize=${pageSize}`,
        method: 'GET',
        headers: config.headers
    })
}

// 获取视频详情
export const reqVideoInfo = (id) => {
    const config = {
        headers: {
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        }
    };
    return requests({
        url: `/video/videoInfo?videoId=${id}`,
        method: "GET",
        headers: config.headers
    })
}

// 发布评论
export const reqPostComment = (data) => {
    const config = {
        headers: {
            'token': getToken(),
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Content-Type': 'application/json'
        }
    };
    return requests({
        url: "/comment/publish",
        method: "POST",
        data,
        headers: config.headers
    })
}

export default {
    reqUserLogin,
    reqUserRegister,
    reqNavMenu,
    reqUploadVideo,
    reqUploadText,
    reqHotVideo，
    reqVideoInfo
}